package cn.yitun.chat.yitunserverimcore.general.main.push.contact;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.data.base.contact.ContactAddResult;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.contact.ContactPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 
 * Date 2019-01-27 21:43:21<br>
 * Description
 * 
 * @author yitun<br>
 * @since 1.1
 */
@Service
public class ContactPush {
	//1.2.101
	final String action = ActionTypeConstant.CONTACT_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 
	 * Date 2019-01-27 19:24:21<br>
	 * Description 推送收到请求被添加为联系人消息
	 * 
	 * @author yitun<br>
	 * @param key
	 * @param applyId
	 * @param userId
	 * @since 1.1
	 */
	public void pushAddApply(Long key, Long applyId, Long userId) {
		String method = ContactPushMethodEnum.ADD_APPLY_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("applyId", applyId);
		writeHandler.push(userId, message);
	}

	/**
	 * 
	 * Description 请求添加为联系人，被添加人处理后推送给请求人 <br>
	 * Date 2019-05-12 15:29:07<br>
	 * 
	 * @param key
	 * @param handle
	 * @param userId void
	 * @version 1.1
	 */
	public void pushApplyHandle(Long key, ContactAddResult handle, Long userId) {
		String method = ContactPushMethodEnum.APPLY_HANDLE_PUSH.getMethod();
		PushMessage pm = PushMessageBuild.build(key, action, method);
		pm.put("result", handle);
		writeHandler.push(userId, pm);
	}

	public void pushUpdateBlocked(Long key, Long contactUserId, String isBlocked, Long userId) {
		String method = ContactPushMethodEnum.UPDATE_BLOCKED_PUSH.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("contactUserId", contactUserId);
		message.bodyPut("isBlocked", isBlocked);
		writeHandler.push(userId, message);
	}
}
